//- Copyright (C) 2023 Beijing Huaxia Chunsong Technology Co., Ltd. 
//- <https://www.chatopera.com>, Licensed under the Chunsong Public 
//- License, Version 1.0  (the "License"), https://docs.cskefu.com/licenses/v1.html
//- Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
//- Copyright (C) 2018-Jun. 2023 Chatopera Inc, <https://www.chatopera.com>
//- Licensed under the Apache License, Version 2.0
//- http://www.apache.org/licenses/LICENSE-2.0
extends /apps/include/layout.pug

include /mixins/client.mixin.pug

block append head
    script(src="/js/CSKeFu_Rest_Request.v1.js")
    script(src="/js/CSKeFu_Agent_Invite.v1.js")
    script.
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage, layer = layui.layer;

            laypage({
                cont: 'page',
                pages: #{onlineUserList ? onlineUserList.totalPages : 0},
                curr: #{onlineUserList ? onlineUserList.number + 1 : 0},
                groups: 5,
                jump: function (data, first) {
                    if (!first) {
                        location.href = "/apps/onlineuser.html?p=" + data.curr;
                    }
                }
            });
            var msg = '#{msg}';
            if (msg == 'username_exist')
                layer.msg('用户名存在，请重新填写', {icon: 2, time: 3000})
            else if (msg == 'email_exist')
                layer.msg('邮件存在，请重新填写', {icon: 2, time: 3000})
            else if (msg == 'mobile_exist')
                layer.msg('手机存在，请重新填写', {icon: 2, time: 3000})
        });

block content
    .layui-side.layui-bg-black.layui-left-black
        .layui-side-scroll
            include include/left
    .layui-body
        .layui-side-scroll
            .row
                .col-lg-12(style="position: relative;")
                    div(style="position: absolute; right: 0; z-index: 10; padding: 7px;")
                        i.layui-icon(style="font-size: 20px; cursor:pointer;", onclick="location.reload()") ဂ
                    h1.site-h1
                        | 在线客服业务概况
                    .row
                        .col-lg-3
                            .ukefu-measure
                                a.ukefu-bt(href="/apps/onlineuser.html")
                                    i.layui-icon.ukewo-btn.ukefu-measure-btn 
                                    .ukefu-bt-text
                                        .ukefu-bt-text-title(style="font-weight:400;font-size:19px;") #{webIMInvite.inviteusers}/#{webIMInvite.refuseusers}
                                        .ukefu-bt-text-content(style="") 访客：已邀请/已拒绝
                        .col-lg-3
                            .ukefu-measure
                                a.ukefu-bt(href="/service/agent/index.html")
                                    i.kfont.icon-iconfontagent.ukewo-btn.ukefu-measure-btn.ukefu-bg-color-yellow
                                    .ukefu-bt-text
                                        #agentReportAgents.ukefu-bt-text-title(style="font-weight:400;font-size:19px;") #{agentReport.agents}/#{agents}
                                        .ukefu-bt-text-content(style="") 坐席:在线/全部
                        .col-lg-3
                            .ukefu-measure
                                a.ukefu-bt(href="/service/quene/index.html")
                                    i.layui-icon.ukewo-btn.ukefu-measure-btn.ukefu-bg-color-pink 
                                    .ukefu-bt-text
                                        .ukefu-bt-text-title(style="font-weight:400;font-size:19px;") #{agentReport.users}/#{agentReport.inquene}
                                        .ukefu-bt-text-content(style="") 会话：服务/排队
                        .col-lg-3
                            .ukefu-measure
                                a.ukefu-bt(href="/apps/onlineuser.html")
                                    i.layui-icon.ukewo-btn.ukefu-measure-btn.ukefu-bg-color-green 
                                    .ukefu-bt-text
                                        .ukefu-bt-text-title(style="font-weight:400;font-size:19px;") #{webIMReport.ipnums}/#{webIMReport.pvnums}
                                        .ukefu-bt-text-content(style="") 统计:IP/PV
            .row
                .col-lg-12
                    h1.site-h1(style="border-top:1px solid #e6e6e6;margin-top:15px;")
                        | 当前在线用户列表 #{onlineUserList ? onlineUserList.totalElements : ''}
                    table.layui-table(lay-skin="line", style="word-wrap:break-word; word-break:break-all;table-layout: fixed")
                        thead
                            tr.design-sortable-tr
                                th 用户名
                                th 终端
                                th 操作系统
                                th 浏览器
                                th 访问时间
                                th 停留时间
                                th 地域
                                th 邀请
                                th 拒绝
                                th(width="100px") 操作
                        tbody
                            if onlineUserList && onlineUserList.content && !onlineUserList.content.isEmpty()
                                for onlineuser in onlineUserList.content
                                    tr.tdHasContorllor.design-dropable-td
                                        td.first_td_head
                                            a(href="/service/online/index.html?userid=" + onlineuser.userid)
                                                | #{onlineuser.username}
                                                if onlineuser.contacts
                                                    | （#{onlineuser.contacts.name}）
                                        td.ukefu-online-client
                                            +device(onlineuser.mobile)
                                        td.ukefu-online-client
                                            +opersystem(onlineuser.opersystem)
                                        td= onlineuser.browser
                                        td= pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', onlineuser.createtime)
                                        td.minSize #{pugHelper.padRight(onlineuser.betweentime / (1000 * 60 * 60), '00')}:#{pugHelper.padRight((onlineuser.betweentime % (1000 * 60 * 60)) / (1000 * 60), "00")}:#{pugHelper.padRight((onlineuser.betweentime % (1000 * 60)) / (1000), "00")}
                                        td= onlineuser.region
                                        td(id="it-" + onlineuser.id)= onlineuser.invitetimes
                                        td(id="rt-" + onlineuser.id)= onlineuser.refusetimes
                                        td(style="white-space: nowrap")
                                            if onlineuser.invitestatus == 'invite'
                                                small.layui-btn.layui-btn-mini.layui-btn-warm(title="访客已邀请") 已邀请
                                            else if onlineuser.invitestatus == 'inserv'
                                                small.layui-btn.layui-btn-mini(title="对话中") 对话中
                                            else if onlineuser.invitestatus == 'refuse'
                                                a.layui-btn.layui-btn-mini.layui-btn-danger(href="javascript:;", name="#{onlineuser.id}", title="访客已拒绝邀请", onclick="sendInvitationToOnlineUser('#{onlineuser.id}', false)") 再次邀请
                                            else
                                                a.layui-btn.layui-btn-mini.layui-btn-normal(href="javascript:;", name="#{onlineuser.id}", title="邀请访客", onclick="sendInvitationToOnlineUser('#{onlineuser.id}', true)") 邀请
                                            a.layui-btn.layui-btn-mini.layui-btn-normal(href="/service/trace.html?sessionid=#{onlineuser.sessionid}&userid=#{onlineuser.id}", title="查看访客轨迹", data-toggle="ajax", data-width="1050") 轨迹

                            else
                                td(colspan="10", style="height:400px;")
                                    .ukefu-empty(style="background: none;")
                                        i.layui-icon 
                                        div(style="") 还没有在线访客记录


            .row(style="padding:5px;")
                #page.col-lg-12(style="text-align:center;")
